<!DOCTYPE HTML>
<html lang="en">
<head>
<title>PixelGetColor - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The PixelGetColor command retrieves the color of the pixel at the specified x,y coordinates." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>PixelGetColor</h1>

<p>Retrieves  the color of the pixel at the specified x,y coordinates.</p>

<pre class="Syntax"><span class="func">PixelGetColor</span>, OutputVar, X, Y <span class="optional">, Mode</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>OutputVar</dt>
  <dd><p>The name of the variable in which to store the color ID in hexadecimal blue-green-red (BGR) format. For example, the color purple is defined 0x800080 because it has an intensity of 80 for its blue and red components but an intensity of 00 for its green component.</p></dd>

  <dt>X, Y</dt>
  <dd><p>The X and Y coordinates of the pixel, which can be <a href="../Variables.htm#Expressions">expressions</a>. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p></dd>

  <dt>Mode</dt>
  <dd><p>This parameter may contain zero or more of the following words. If more than one word is present, separate each from the next with a space (e.g. <code>Alt RGB</code>).</p>
      <p><strong>Alt</strong> <span class="ver">[v1.0.43.10+]:</span> Uses an alternate method to retrieve the color, which should be used when the normal method produces invalid or inaccurate colors for a particular type of window. This method is about 10% slower than the normal method.</p>
      <p><strong>Slow</strong> <span class="ver">[v1.0.43.10+]:</span> Uses a more elaborate method to retrieve the color, which may work in certain full-screen applications when the other methods fail. This method is about three times slower than the normal method. Note: <em>Slow</em> takes precedence over <em>Alt</em>, so there is no need to specify <em>Alt</em> in this case.</p>
      <p><strong>RGB</strong>: Retrieves the color in RGB vs. BGR format. In other words, the red and the blue components are swapped. This is useful for retrieving colors compatible with <a href="WinSet.htm">WinSet</a>, <a href="Gui.htm">Gui</a>, <a href="Progress.htm">Progress</a>, and <a href="Progress.htm">SplashImage</a>.</p></dd>

</dl>

<h2>Error Handling</h2>
<p><span class="ver">[v1.1.04+]</span>: This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h2>Remarks</h2>
<p>The pixel must be visible; in other words, it is not possible to retrieve the pixel color of a window hidden behind another window. By contrast, pixels beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will hide any pixels beneath them.</p>
<p>Use Window Spy (available in tray icon menu) or the example at the bottom of this page to determine the colors currently on the screen.</p>
<p>Known limitations:</p>
<ul>
  <li>A window that is <a href="WinSet.htm#trans">partially transparent</a> or that has one of its colors marked invisible (<a href="WinSet.htm#TransColor">TransColor</a>) typically yields colors for the window behind itself rather than its own.</li>
  <li>PixelGetColor might not produce accurate results for certain applications. If this occurs, try specifying the word <em>Alt</em> or <em>Slow</em> in the last parameter.</li>
</ul>
<h2>Related</h2>
<p><a href="PixelSearch.htm">PixelSearch</a>, <a href="ImageSearch.htm">ImageSearch</a>, <a href="CoordMode.htm">CoordMode</a>, <a href="MouseGetPos.htm">MouseGetPos</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>^!z::  <em>; Control+Alt+Z hotkey.</em>
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
MsgBox The color at the current cursor position is %color%.
return</pre>
</div>

</body>
</html>
